package com.itboye.eweilisten.presenter;

import com.itboye.eweilisten.interfaces.TiMuInterface;
import com.itboye.eweilisten.me.personal.model.PersonDataBean;
import com.itboye.eweilisten.responsitory.TiMuResponsitory;
import com.itboye.eweilisten.volley.BasePresenter;
import com.itboye.eweilisten.volley.ICompleteListener;
import com.itboye.eweilisten.volley.ResultEntity;

import java.util.Observer;

/**
 * 做题.
 */
public class TiMuPresenter extends BasePresenter implements TiMuInterface<PersonDataBean> {
    // 做题
    public static final String zuoti_success = TiMuPresenter.class.getName()
            + "_zuoti_success";
    public static final String zuoti_fail = TiMuPresenter.class.getName()
            + "_zuoti_fail";

    // 题目详情
    public static final String zuoti_xq_success = TiMuPresenter.class.getName()
            + "_zuoti_xq_success";
    public static final String zuoti_xq_fail = TiMuPresenter.class.getName()
            + "_zuoti_xq_fail";

    // 提交答案
    public static final String tijiao_success = TiMuPresenter.class.getName()
            + "_tijiao_success";
    public static final String tijiao_fail = TiMuPresenter.class.getName()
            + "_tijiao_fail";

    public TiMuPresenter(Observer observer) {
        super(observer);
    }

    @Override
    public void onTiMu(String dt_type) {
        TiMuInterface<PersonDataBean> user = new TiMuResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(zuoti_success);
                        TiMuPresenter.this.setChanged();
                        TiMuPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(zuoti_fail);
                        TiMuPresenter.this.setChanged();
                        TiMuPresenter.this.notifyObservers(result);

                    }
                });
        user.onTiMu(dt_type);
    }
    @Override
    public void onXiangQing(String uid,String unit_id,String s_id) {
        TiMuInterface<PersonDataBean> user = new TiMuResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(zuoti_xq_success);
                        TiMuPresenter.this.setChanged();
                        TiMuPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(zuoti_xq_fail);
                        TiMuPresenter.this.setChanged();
                        TiMuPresenter.this.notifyObservers(result);

                    }
                });
        user.onXiangQing(uid,unit_id,s_id);
    }

    /**
     * 提交答案
     * @param uid
     * @param unit_id
     * @param use_time
     * @param answer_multi
     */
    @Override
    public void onTiJiao(String uid, String unit_id, String use_time, String answer_multi) {
        TiMuInterface<PersonDataBean> user = new TiMuResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(tijiao_success);
                        TiMuPresenter.this.setChanged();
                        TiMuPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(tijiao_fail);
                        TiMuPresenter.this.setChanged();
                        TiMuPresenter.this.notifyObservers(result);

                    }
                });
        user.onTiJiao(uid,unit_id,use_time,answer_multi);
    }
}
